package br.org.isvi.interpretador.portugol.access;

import java.util.HashMap;
import java.util.List;

import org.apache.cayenne.exp.Expression;
import org.apache.cayenne.query.SelectQuery;
import org.apache.derby.tools.sysinfo;

import br.org.isvi.interpretador.portugol.model.Aula;
import br.org.isvi.interpretador.portugol.model.Exercicio;
import br.org.isvi.interpretador.portugol.model.Nivel;

public class ExercicioDAO extends AbstractDAO<Exercicio> {

	@Override
	public Class<Exercicio> getType() {
		return Exercicio.class;
	}
	
	@SuppressWarnings("unchecked")
	public List<Exercicio> obterPorAula(Aula aula) {
		List<Exercicio> ret;
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("aulaId", aula.getId());
		
		
		SelectQuery query = new SelectQuery(Exercicio.class, Expression.fromString("aula = $aulaId "));
		
		ret = getCtx().performQuery(query.queryWithParameters(map));
		
		return ret;
	}
	
	@SuppressWarnings("unchecked")
	public List<Exercicio> obterPorNivel(Nivel model) {
		List<Exercicio> ret;
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("nivelId", model.getId());
		
		SelectQuery query = new SelectQuery(Exercicio.class, Expression.fromString("toNivel = $nivelId "));
		
		ret = getCtx().performQuery(query.queryWithParameters(map));
		
		return ret;
	}
	
	@SuppressWarnings("unchecked")
	public List<Exercicio> obterAvulsosPorNivel(Nivel model) {
		List<Exercicio> ret;
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("nivelId", model.getId());
		
		SelectQuery query = new SelectQuery(Exercicio.class, Expression.fromString("toNivel = $nivelId and liberado = 1"));
		
		ret = getCtx().performQuery(query.queryWithParameters(map));
		
		return ret;
	}
//	
//	public static void main(String[] args) {
//		
//		List l = new ExercicioDAO().obterPorNivel(new Integer(200));
//		System.out.println("");
//	}
}
